﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using NASA.BeAMartian.Model;
using NASA.BeAMartian.Helper;
using Microsoft.TownHall.ServiceClient;

namespace NASA.BeAMartian.Views
{
    public partial class Profile : PhoneApplicationPage
    {
        public Profile()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Profile_Loaded);
        }

        void Profile_Loaded(object sender, RoutedEventArgs e)
        {
            if (ApplicationContext.Instance.UserData == null || ApplicationContext.Instance.UserData.UserID == 0)
            {
                
            }
            else
            {
                tbUserName.Text = ApplicationContext.Instance.UserData.DisplayName.Replace("\r\n", "");
                tbCitizenType.Text = ApplicationContext.Instance.UserData.CitizenType;
                imgAvatar.Source = new BitmapImage(new Uri(String.Format(
                    "http://beamartian.jpl.nasa.gov/s/img/avatars/avatar-{0}-lg.jpg",
                    ApplicationContext.Instance.UserData.Avatar), UriKind.Absolute)); 
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var store = new PersistentDataStorage();
            ApplicationContext.Instance.UserData = null;
            store.Backup("User", new User());
            this.NavigationService.Navigate(new Uri("/Welcome.xaml", UriKind.Relative));
        }
    }
}